import unittest

from imageSeq   import ImageSequence
from fileListerTests import MockFileLister

class ImageSequenceTest(unittest.TestCase):
	
	def setUp(self):
		self.imageSeq = ImageSequence()
		self.imageSeq.setFileLister(MockFileLister())


	def testIsValid_true(self):
		self.imageSeq.setFormat("/tmp/images.#.dpx")
		self.assertTrue(self.imageSeq.isValid())
		
		
	def testIsValid_false(self):
		self.imageSeq.setFormat("/tmp/images.dpx")
		self.assertFalse(self.imageSeq.isValid())
		
		
	def testIsValid_falseBadExt(self):
		self.imageSeq.setFormat("/tmp/images.#.jpg")
		self.assertFalse(self.imageSeq.isValid())
		
		
	def testIsValid_falseBadFramesPos(self):
		self.imageSeq.setFormat("/tmp/images.#.bla.dpx")
		self.assertFalse(self.imageSeq.isValid())
		
		
	def testFileMatches_true(self):
		self.imageSeq.setFormat("images.#.dpx")
		self.assertTrue(self.imageSeq.fileMatches("images.0001.dpx"))
	
		
	def testFileMatches_falseFramePadding(self):
		self.imageSeq.setFormat("images.#.dpx")
		self.assertFalse(self.imageSeq.fileMatches("images.001.dpx"))
		

	def testFileMatches_falseNoFrame(self):
		self.imageSeq.setFormat("images.#.dpx")
		self.assertFalse(self.imageSeq.fileMatches("images.wxyz.dpx"))

		
	def testGetFilesThatMatch(self):
		self.imageSeq.setFormat("/tmp/images.#.dpx")
		files = ["/tmp/images.0001.dpx", "/tmp/XYZ.0001.dpx", "/tmp/images.0010.dpx" ]
		filesThatMatch =  ["/tmp/images.0001.dpx", "/tmp/images.0010.dpx" ]
		self.assertEquals(filesThatMatch, self.imageSeq.getFilesThatMatch(files))
		
		
	def testGetFilesThatMatch_2(self):
		self.imageSeq.setFormat("/tmp/images.#.dpx")
		files = ["/tmp/images.001.dpx", "/tmp/XYZ.0001.dpx", "/tmp/images.0010.jpg" ]
		filesThatMatch =  []
		
		self.assertEquals(filesThatMatch, self.imageSeq.getFilesThatMatch(files))

		
	def testGetFilesThatMatchInDir(self):
		self.imageSeq.setFormat("/tmp/images.#.dpx")
		filesThatMatch =  ["/tmp/images.0001.dpx", "/tmp/images.0010.dpx" ]
		
		self.assertEquals(filesThatMatch, self.imageSeq.getFilesThatMatchInDir("/tmp"))
		
		
if __name__ == '__main__':
	unittest.main()

	
	
	